import {getStorage} from './storage'

/**
 * 一些公共方法
 */

 export const loginif=()=>{
  const iflogin=getStorage("iflogin");
  if(!iflogin){
    return false;
  }
  return true;
 }

 /**
  * 随机头像和名字
  */
 export const randomNameOrImg=()=>{
   let imgstr='';
   let namestr='';
   let user={};
   const img=["/images/guess/毛巾卷.png","/images/guess/抹茶大福.png","/images/guess/蜜糖布丁.png","/images/guess/牛角包.png","/images/guess/苹果派.png","/images/guess/曲奇饼干.png","/images/guess/舒芙蕾.png","/images/guess/甜甜圈.png"
  ]
  let intInclusive = Math.floor(Math.random() * img.length);
  imgstr=img[intInclusive];
  const name=['焦躁的布丁','破产的美团','崩盘的小龙虾','天子娇子','你是狼人','女巫','可爱的基拉祈','黄皮耗子','永远十岁的小智','可爱捏','无语子','始皇帝']
  intInclusive = Math.floor(Math.random() * name.length);
  namestr=name[intInclusive];
  user={
    "username":namestr,
    "userurl":imgstr
  }
  return user;
 }
/**
 * 日期转换 时分秒
 */
 export const timeTransitionTime=(time)=>{
  const endtime = new Date(time).toLocaleDateString('zh-CN', {
    year: 'numeric',
    month: '2-digit',
    day: '2-digit',
    hour12: false, // 24小时制
    hour: '2-digit',
    minute: '2-digit',
    second: '2-digit'
  }).replace(/\//g, '-');
  return endtime;
 }
/**
 * 日期转换 没有时分秒
 * @param {*} time 
 */
 export const timeTransition=(time)=>{
  const endtime = new Date(time).toLocaleDateString('zh-CN', {
    year: 'numeric',
    month: '2-digit',
    day: '2-digit'
  }).replace(/\//g, '-');
  return endtime;
 }